/*
 *  Copyright (C) 2010:
 *                 Buzzanca Marco <marco.bzn@gmail.com>
 *         Monaco Davide Giuseppe <black.ralkass@gmail.com>
 *              Petralia Veronica <veronicapetralia@gmail.com>
 *
 * This file is part of DS2011BMP
 *
 * DS2011BMP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DS2011BMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file workerdiscoveryproxy.cpp
 * @author Marco Buzzanca
 *
 * This file contains WorkerDiscoveryProxy class implementation.
 */

#include "workerdiscoveryproxy.h"

WorkerDiscoveryProxy::WorkerDiscoveryProxy()
  : _client() { }

WorkerDiscoveryProxy::WorkerDiscoveryProxy(const std::string& IP,
                                           boost::uint16_t port)
  : _client(IP, port) { }

WorkerDiscoveryProxy::WorkerDiscoveryProxy(const Address& address)
  : _client(address) { }

WorkerDiscoveryProxy::~WorkerDiscoveryProxy() { }

const Address& WorkerDiscoveryProxy::getAddr() const
{ return _client.getAddress(); }

void WorkerDiscoveryProxy::setAddr(const std::string& IP, boost::uint16_t port)
{ _client.setAddress(IP, port); }

void WorkerDiscoveryProxy::setAddr(const Address& address)
{ _client.setAddress(address); }

Address WorkerDiscoveryProxy::getWorker(const TaskDescriptor& td)
{
    Address worker_addr;

    _client.resolve();
    _client << td;

    // Deserialization, write into worker_addr.
    _client >> worker_addr;

    return worker_addr;
}

void WorkerDiscoveryProxy::addWorker(const WorkerDescriptor& wd)
{
    // Not yet implemented
}

void WorkerDiscoveryProxy::updateWorker(size_t index, const WorkerDescriptor& wd)
{
    // Not yet implemented
}
